#include "projectmanager.h"

class M_Code_Project;
class M_Code_AuiNotebook;
class FilesGroupsAndMasks;
class wxAuiNotebookEvent;

class ProjectManagerUI : public wxEvtHandler, public cbProjectManagerUI {
  public:
    ProjectManagerUI();
    ~ProjectManagerUI();
    M_Code_AuiNotebook* GetNotebook() { return m_pNotebook; }
    M_Code_TreeCtrl* GetTree() { return m_pTree; }
    wxTreeItemId GetTreeSelection();
    void RebuildTree();
    void FreezeTree();
    void UnfreezeTree( bool force = false );
    void UpdateActiveProject( M_Code_Project* oldProject, M_Code_Project* newProject, bool refresh );
    void RemoveProject( M_Code_Project* project );
    void BeginLoadingWorkspace();
    void CloseWorkspace();
    void FinishLoadingProject( M_Code_Project* project, bool newAddition, M_Code_unused FilesGroupsAndMasks* fgam );
    void FinishLoadingWorkspace( M_Code_Project* activeProject, const wxString &workspaceTitle );
    void ShowFileInTree( ProjectFile &projectFile );
    bool QueryCloseAllProjects();
    bool QueryCloseProject( M_Code_Project* project, bool dontsavefiles );
    bool QueryCloseWorkspace();
    int AskForBuildTargetIndex( M_Code_Project* project );
    wxArrayInt AskForMultiBuildTargetIndex( M_Code_Project* project );
    void ConfigureProjectDependencies( M_Code_Project* base );
    void CheckForExternallyModifiedProjects();
  private:
    void InitPane();
    void BuildTree();
    void SwitchToProjectsPage();
    void ShowMenu( wxTreeItemId id, const wxPoint& pt );
    void CreateMenuTreeProps( wxMenu* menu, bool popup );
    void DoOpenFile( ProjectFile* pf, const wxString& filename );
    void DoOpenSelectedFile();
    void RemoveFilesRecursively( wxTreeItemId& sel_id );
    void OpenFilesRecursively( wxTreeItemId& sel_id );
  private:
    void OnTabContextMenu( wxAuiNotebookEvent& event );
    void OnTabPosition( wxCommandEvent& event );
    void OnProjectFileActivated( wxTreeEvent& event );
    void OnExecParameters( wxCommandEvent& event );
    void OnTreeItemRightClick( wxTreeEvent& event );
    void OnTreeBeginDrag( wxTreeEvent& event );
    void OnTreeEndDrag( wxTreeEvent& event );
    void OnRightClick( wxCommandEvent& event );
    void OnRenameWorkspace( wxCommandEvent& event );
    void OnSaveWorkspace( wxCommandEvent& event );
    void OnSaveAsWorkspace( wxCommandEvent& event );
    void OnCloseWorkspace( wxCommandEvent& event );
    void OnSetActiveProject( wxCommandEvent& event );
    void OnAddFilesToProjectRecursively( wxCommandEvent& event );
    void OnAddFileToProject( wxCommandEvent& event );
    void OnRemoveFileFromProject( wxCommandEvent& event );
    void OnRenameFile( wxCommandEvent& event );
    void OnSaveProject( wxCommandEvent& event );
    void OnCloseProject( wxCommandEvent& event );
    void OnSaveFile( wxCommandEvent& event );
    void OnCloseFile( wxCommandEvent& event );
    void OnOpenFile( wxCommandEvent& event );
    void OnOpenFolderFiles( wxCommandEvent& event );
    void OnOpenWith( wxCommandEvent& event );
    void OnProperties( wxCommandEvent& event );
    void OnFileOptions( wxCommandEvent &event );
    void OnNotes( wxCommandEvent& event );
    void OnGotoFile( wxCommandEvent& event );
    void OnViewCategorize( wxCommandEvent& event );
    void OnViewUseFolders( wxCommandEvent& event );
    void OnViewHideFolderName( wxCommandEvent& event );
    void OnViewFileMasks( wxCommandEvent& event );
    void OnFindFile( wxCommandEvent& event );
    wxArrayString ListNodes( wxTreeItemId node ) const;
    void OnBeginEditNode( wxTreeEvent& event );
    void OnEndEditNode( wxTreeEvent& event );
    void OnAddVirtualFolder( wxCommandEvent& event );
    void OnDeleteVirtualFolder( wxCommandEvent& event );
    void OnRenameVirtualFolder( wxCommandEvent& event );
    void OnUpdateUI( wxUpdateUIEvent& event );
    void OnIdle( wxIdleEvent& event );
    void OnKeyDown( wxTreeEvent& event );
    void MoveProjectUp( M_Code_Project* project, bool warpAround = false );
    void MoveProjectDown( M_Code_Project* project, bool warpAround = false );
    void BuildProjectTree( M_Code_Project* project, M_Code_TreeCtrl* tree, const wxTreeItemId& root,
                           int ptvs, FilesGroupsAndMasks* fgam );

  private:
    M_Code_AuiNotebook* m_pNotebook;
    M_Code_TreeCtrl* m_pTree;
    wxTreeItemId m_TreeRoot;
    wxImageList* m_pImages;
    int m_TreeVisualState;
    int m_TreeFreezeCounter;
    wxArrayTreeItemIds m_DraggingSelection;
    wxTreeItemId m_RightClickItem;
    bool m_isCheckingForExternallyModifiedProjects;
  private:
    DECLARE_EVENT_TABLE()
};

class BatchProjectManagerUI : public cbProjectManagerUI {
  public:
    M_Code_AuiNotebook* GetNotebook() override { return nullptr; }
    M_Code_TreeCtrl* GetTree() override { return nullptr; }
    void RebuildTree() override {}
    void FreezeTree() override {}
    void UnfreezeTree( bool force = false ) override {}
    wxTreeItemId GetTreeSelection() override { return wxTreeItemId(); }
    void ShowFileInTree( ProjectFile &projectFile ) override {}
    void UpdateActiveProject( M_Code_Project *oldProject, M_Code_Project *newProject, bool refresh ) override {}
    void RemoveProject( M_Code_Project *project ) override {}
    void BeginLoadingWorkspace() override {}
    void CloseWorkspace() override {}
    void FinishLoadingProject( M_Code_Project *project, bool newAddition, FilesGroupsAndMasks* fileGroups ) override {}
    void FinishLoadingWorkspace( M_Code_Project *activeProject, const wxString &workspaceTitle ) override {}
    bool QueryCloseAllProjects() override { return true; }
    bool QueryCloseProject( M_Code_Project *proj, bool dontsavefiles = false ) override { return true; }
    bool QueryCloseWorkspace() override { return true; }
    int AskForBuildTargetIndex( M_Code_Project* project = nullptr ) override { return -1; }
    wxArrayInt AskForMultiBuildTargetIndex( M_Code_Project* project = nullptr ) override { return wxArrayInt(); }
    void ConfigureProjectDependencies( M_Code_Project* base = nullptr ) override {}
    void SwitchToProjectsPage() override {}
};
